package com.mz.mattress.client.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mz.mattress.api.entity.OrderUseTimes;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface OrderUseTimesMapper extends BaseMapper<OrderUseTimes> {

    @Select("select * from mz_order_use_times where order_id=#{orderId} and deleted=0 order by id desc")
    List<OrderUseTimes> list(@Param("orderId") Long orderId);

    IPage<OrderUseTimes> listPage(Page page, @Param("memberId") Long memberId);

//    @Select("select * from mz_order_use_times where status=#{status} and member_id=#{memberId} and deleted=0 order by id desc")
//    List<OrderUseTimes> listByStatus(@Param("status") Integer status, @Param("memberId") Long memberId);

    @Select("select * from mz_order_use_times where status in (0,1,2) and member_id=#{memberId} and deleted=0 order by id desc")
    List<OrderUseTimes> doingList(@Param("memberId") Long memberId);

    @Select("select * from mz_order_use_times where device_code=#{deviceCode} and member_id=#{memberId} and deleted=0 order by id desc limit 1")
    OrderUseTimes selectOneByMemberIdDeviceCode(@Param("memberId") Long memberId, @Param("deviceCode") String deviceCode);

//    @Select("select * from mz_order_use_times where end_time<now() and status=1 and plan=0")
//    List<OrderUseTimes> selectOvertime();

    //找未启动的订单
    @Select("select * from mz_order_use_times where create_time<#{endTime} and status=0")
    List<OrderUseTimes> selectNotStart(@Param("endTime") String endTime);

    @Select("select * from mz_order_use_times where end_time<#{endTime} and status in (1,2) and plan=0")
    List<OrderUseTimes> selectOvertime(@Param("endTime") String endTime);

//    @Select("select * from mz_order_use_times where order_id=#{orderId} and deleted=0 order by id desc limit 1")
//    OrderUseTimes selectByOrderId(@Param("orderId") Long orderId);

    List<OrderUseTimes> reportByMemberId(@Param("memberId") Long memberId);

    //找待发佣金列表
    @Select("select id from mz_order_use_times where status=3 and bonus_send=0")
    List<Integer> selectIds();

//    @Select("select * from mz_order_use_times where order_id=#{orderId} and deleted=0 order by id desc limit 1")
//    OrderUseTimes selectByOrderId(@Param("orderId") Long orderId);

}
